//
//  PayViewController.m
//  项目三
//
//  Created by rimi on 15/9/28.
//  Copyright (c) 2015年 rimi. All rights reserved.
//

#import "PayViewController.h"
#import "DelegatePayView.h"
#import "CardPayView.h"

@interface PayViewController () {

    UIButton *_delegatePayBtn;   /**< 代理缴费 */
    UIButton *_cardPayBtn;      /**< 畅通卡缴费 */
}


@property (nonatomic, strong) DelegatePayView *delegatePayView;
@property (nonatomic, strong) CardPayView *cardPayView;

- (void)initializeUserInterface; /**< 初始化用户界面 */

@end

@implementation PayViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    [self initializeUserInterface];
}

- (void)initializeUserInterface {
    
    self.titleImageView.image = [UIImage imageNamed:@"缴费服务-logo"];
    [super initializeUserInterface];
    
    _delegatePayBtn = [[UIButton alloc] initWithFrame:DHFlexibleFrame(CGRectMake(200, 27, 100, 33))];
    _delegatePayBtn.selected = YES;
    [_delegatePayBtn setImage:[UIImage imageNamed:@"未选中 代理缴费"] forState:UIControlStateNormal];
    [_delegatePayBtn setImage:[UIImage imageNamed:@"选中 代理缴费"] forState:UIControlStateSelected];
    [_delegatePayBtn addTarget:self action:@selector(actionOnDelegatePayBtn) forControlEvents:UIControlEventTouchUpInside];
    
    _cardPayBtn = [[UIButton alloc] initWithFrame:DHFlexibleFrame(CGRectMake(315, 27, 100, 33))];
    _cardPayBtn.selected = NO;
    [_cardPayBtn setImage:[UIImage imageNamed:@"未选中 畅通卡缴费"] forState:UIControlStateNormal];
    [_cardPayBtn setImage:[UIImage imageNamed:@"选中 畅通卡缴费"] forState:UIControlStateSelected];
    [_cardPayBtn addTarget:self action:@selector(actionOnCardPayBtn) forControlEvents:UIControlEventTouchUpInside];
    
    [self.view addSubview:_delegatePayBtn];
    [self.view addSubview:_cardPayBtn];
    
    
    [UIView animateWithDuration:1.0 animations:^{
        self.delegatePayView.alpha = 1;
    }];
    
    [self.view addSubview:self.delegatePayView];
    

}


#pragma mark - action on btn
- (void)actionOnDelegatePayBtn {

    [self removeView:self.cardPayView];
    [self removeView:(UIView *)self.cardPayView.ticketView];
    [self removeView:(UIView *)self.cardPayView.licenceView];
    [self removeView:(UIView *)self.cardPayView.numberView];
    
    [self.view addSubview:self.delegatePayView];
    
    _delegatePayBtn.selected = YES;
    _cardPayBtn.selected = NO;
    
    [UIView animateWithDuration:1.0 animations:^{
        self.delegatePayView.alpha = 1;
    }];
}

- (void)actionOnCardPayBtn {

    
    [self removeView:self.delegatePayView];
    [self removeView:(UIView *)self.cardPayView.ticketView];
    [self removeView:(UIView *)self.cardPayView.licenceView];
    [self removeView:(UIView *)self.cardPayView.numberView];
    
    [self.view addSubview:self.cardPayView];
    
    _delegatePayBtn.selected = NO;
    _cardPayBtn.selected = YES;
    
    [UIView animateWithDuration:1.0 animations:^{
        self.cardPayView.alpha = 1;
    }];

}
#pragma mark - private method
- (void)removeView:(UIView *)view {
    
    [UIView animateWithDuration:0.6 animations:^{
        view.alpha = 0;
    } completion:^(BOOL finished) {
        [view removeFromSuperview];
    }];
}
#pragma mark - getter
- (DelegatePayView *)delegatePayView {

    if (!_delegatePayView) {
        _delegatePayView = ({
        
            DelegatePayView *view = [[DelegatePayView alloc] initWithFrame:DHFlexibleFrame(CGRectMake(0, 82, 708, 944))];
            view.alpha = 0;
            
            view;
        });
    }
    return _delegatePayView;
}
- (CardPayView *)cardPayView {

    if (!_cardPayView) {
        _cardPayView = ({
        
            CardPayView *view = [[CardPayView alloc] initWithFrame:DHFlexibleFrame(CGRectMake(0, 82, 708, 944))];
            
            view.alpha = 0;
            view;
        });
    }
    return _cardPayView;
}


@end
